/*
 * KmyMath.h
 *
 *  Created on: 2012-9-4
 *      Author: KamiyaSoft
 */

#ifndef __KMY_MATH_H_
#define __KMY_MATH_H_

#include "KmyTypedef.h"
//#include "new.h"

#ifdef __cplusplus
extern "C" {
#endif

/** 4字节对齐 */
#define ALIGN4(x) (((x)+3)>>2<<2)
#define ALIGN2(x) (((x)+1)>>1<<1)
#define ALIGN8(x) (((x)+7)>>3<<3)
#define ALIGN16(x) (((x)+15)>>4<<4)
#define ALIGN32(x) (((x)+31)>>5<<5)
#define ALIGN(x, a)			(((x) + ((a) - 1)) & ~((a) - 1)) //a是对齐量
#define MAX(a, b) ((a)>(b)?(a):(b))
#define MIN(a, b) ((a)<(b)?(a):(b))
#define ABS(x)	((x)>0?(x):-(x))

/** 获取最高的二进制位数  */
int getHighestBit(s32 n);
/** 获取大于等于n的最小2的幂数 */
int getSmallest2exp(s32 n);

int power(int a, int b);

int kmy_round(float f);
int kmy_roundup(float f);

u16 RGB16(u8 r, u8 g, u8 b);

int* numToFrame(int n, int length);
#ifdef __cplusplus
}/* extern "C" */
#endif

#endif /* KMYMATH_H_ */
